package com.zjlab.sandtable.utils;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.zjlab.SmConfig;
import com.zjlab.web.config.SpringContextUtil;

/**
 * @author xue
 * @create 2022-11-07 15:43
 */
public class RemoteCall {

    private final static String DESK_TOP_REMOTE_URL = SpringContextUtil.getBean(SmConfig.class).getDeskTopRemoteUrl();

    /**
     * 符合Restful风格的远程调用
     *
     * @param path
     * @param input
     * @param milliseconds
     * @return 返回值是json
     */
    public static String postRestful(String path, Object input, Integer milliseconds) {
        String json = JSONUtil.toJsonStr(input);
        return HttpRequest.post(DESK_TOP_REMOTE_URL + path)
                .body(json)
                .timeout(milliseconds)
                .execute().body();
    }

}
